package com.splic.product.service.impl;

import java.util.Date;
import java.util.List;
import com.splic.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.splic.product.mapper.WeatherIconMapper;
import com.splic.product.domain.WeatherIcon;
import com.splic.product.service.WeatherIconService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 天气情况图标Service业务层处理
 * 
 * @author singe
 * @date 2022-03-17
 */
@Service
public class WeatherIconServiceImpl implements WeatherIconService
{
    @Autowired
    private WeatherIconMapper weatherIconMapper;

    /**
     * 查询天气情况图标
     * 
     * @param id 天气情况图标主键
     * @return 天气情况图标
     */
    @Override
    public WeatherIcon selectWeatherIconById(Long id)
    {
        return weatherIconMapper.selectWeatherIconById(id);
    }

    /**
     * 查询天气情况图标列表
     * 
     * @param weatherIcon 天气情况图标
     * @return 天气情况图标
     */
    @Override
    public List<WeatherIcon> selectPageList(WeatherIcon weatherIcon)
    {
        return weatherIconMapper.selectWeatherIconList(weatherIcon);
    }

    /**
     * 查询天气情况图标列表
     *
     * @param weatherIcon 天气情况图标
     * @return 天气情况图标
     */
    @Override
    public List<WeatherIcon> selectWeatherIconList(WeatherIcon weatherIcon)
    {
        return weatherIconMapper.selectWeatherIconList(weatherIcon);
    }

    /**
     * 新增天气情况图标
     * 
     * @param weatherIcon 天气情况图标
     * @return 结果
     */
    @Override
    public int insert(WeatherIcon weatherIcon)
    {
        weatherIcon.setCreateTime(DateUtils.getNowDate());
        return weatherIconMapper.insert(weatherIcon);
    }

    /**
     * 修改天气情况图标
     * 
     * @param weatherIcon 天气情况图标
     * @return 结果
     */
    @Override
    public int update(WeatherIcon weatherIcon)
    {
        weatherIcon.setUpdateTime(DateUtils.getNowDate());
        return weatherIconMapper.update(weatherIcon);
    }


    /**
     * 删除天气情况图标信息
     * 
     * @param id 天气情况图标主键
     * @return 结果
     */
    @Override
    public int deleteById(Long id)
    {
        return weatherIconMapper.deleteById(id);
    }
    /**
     * 修改天气情况图标
     *
     * @param weatherIcon 天气情况图标信息
     * @return 结果
     */
    @Override
    @Transactional
    @CacheEvict(cacheNames = "weatherIcon:", key = "#weatherIcon.name")
    public int saveOrUpdate(WeatherIcon weatherIcon)
    {
        if(weatherIcon.getId() != null){
            weatherIcon.setUpdateTime(new Date());
            return weatherIconMapper.update(weatherIcon);
        }else{
            weatherIcon.setCreateTime(new Date());
            return weatherIconMapper.insert(weatherIcon);
        }
    }

    @Override
    @Cacheable(cacheNames = "weatherIcon:", key = "#name", unless = "#result == null")
    public WeatherIcon getByName(String name) {
        return weatherIconMapper.getByName(name);
    }
}
